<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Page Title</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
    <script src='main.js'></script>
</head>
<body>
    
</body>
<script>
// 1. 查看字符串中是否包含数字
function hasNumber(str) {
    return /\d/.test(str);
}

console.log('是否包含数字:', hasNumber("abc123")); 
console.log('是否包含数字:', hasNumber("abc"));     
</script>
<script>
    // 2. 验证中文名，且2到5位
function validateChineseName(name) {
    return /^[\u4e00-\u9fa5]{2,5}$/.test(name);
}

console.log('是否有效中文名:', validateChineseName("张三"));   
console.log('是否有效中文名:', validateChineseName("张三丰")); 
console.log('是否有效中文名:', validateChineseName("张"));     
console.log('是否有效中文名:', validateChineseName("张三五六七"));     
</script>
<script>
    // 3. 提取字符串中的所有数字
const str = "中国移动:10086,中国联通:10010,中国电信:10000";
const numbers = str.match(/\d+/g);
console.log('提取的数字:', numbers);    
</script>
<script>
    // 4. 提取年月日的日期中的年份
const dateStr = "2022-10-20";
dateStr.match(/(\d{4})-(\d{2})-(\d{2})/);
console.log('提取的年份:', RegExp.$1);  
</script>
<script>
    // 5. 提取邮箱的各部分
const email = "123456@qq.com";
email.match(/^(\w+)@([^@]+)\.([^.]+)$/);
console.log('用户名:', RegExp.$1); 
console.log('域名:', RegExp.$2);   
console.log('后缀:', RegExp.$3);   
</script>
<script>
    // 6. 将字符串中的空格替换成AAA
const strWithSpaces = "abc   123   aaa   bbb";
const replacedStr = strWithSpaces.replace(/\s+/g, "AAA");
console.log('替换后的字符串:', replacedStr);     
</script>
<script>
    // 7. 切割字符串
const splitStr = "abc#123@bbb";
const parts = splitStr.split(/[#@]/);
console.log('切割后的数组:', parts); 
</script>
</html>